package stu.day9_day18;

import java.util.Stack;

public class LeetCode232 {
    Stack<Integer> instack = new Stack<>();
    Stack<Integer> outstack = new Stack<>();

    public void push(int x) {
        instack.push(x);
    }

    public int pop() {
        int len = instack.size();
        int num;
        while (instack.size()>1){
            outstack.push(instack.pop());
        }
        num = instack.pop();
        while (!outstack.isEmpty()){
            instack.push(outstack.pop());
        }
        return num;
    }

    public int peek() {
        int len = instack.size();
        int num;
        while (instack.size()!=1){
            outstack.push(instack.pop());
        }
        num = instack.peek();
        while (!outstack.isEmpty()){
            instack.push(outstack.pop());
        }
        return num;
    }

    public boolean empty() {
        return instack.isEmpty();
    }

}
